package com.shsxt.util;

import java.util.HashMap;
import java.util.Map;
import cn.jpush.api.push.model.Message.Builder;
import cn.jpush.api.push.model.Options;
import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.JPushClient;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Message;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.AndroidNotification;
import cn.jpush.api.push.model.notification.IosNotification;
import cn.jpush.api.push.model.notification.Notification;

public class Push{
	public static void main(String[] args) throws APIConnectionException, APIRequestException {
		
		push4();
	}
	public static void push() throws APIConnectionException, APIRequestException{
		String materSecret="1dd0e3924e7394137bc20d57";
		String appKey="8f6965a441a0aa10011c7063";
		//阿姨
	/*	String materSecret="b2588d7dcaa473f3975c86fc";
		String appKey="587fc17e9c0cc048c2a3e10a";*/
		JPushClient jPushCilent=new JPushClient(materSecret,appKey);
		PushPayload payload=PushPayload.newBuilder()
				.setPlatform(Platform.all())
				.setAudience(Audience.all())
				.setNotification(Notification.alert("this is a test"))
				.setMessage(Message.content("this is a test"))
				.build();
		PushResult result=jPushCilent.sendPush(payload);
		System.err.println("s:="+result);
		/*PushPayload payload=PushPayload.alertAll("我输出了"); 
		PushResult result=jPushCilent.sendPush(payload);
		System.err.println("s:="+result);*/
	}
	public static void push3() throws APIConnectionException, APIRequestException{
		/*String materSecret="1dd0e3924e7394137bc20d57";
		String appKey="8f6965a441a0aa10011c7063";*/
		//阿姨
		String materSecret="b2588d7dcaa473f3975c86fc";
		String appKey="587fc17e9c0cc048c2a3e10a";
		JPushClient jPushCilent=new JPushClient(materSecret,appKey);
		PushPayload payload=PushPayload.newBuilder()
				 .setPlatform(Platform.all())
	                .setAudience(Audience.alias("15356506227"))/*15356506227,13843838438*/
	                .setNotification(Notification.alert("我承认都是月亮惹得祸!"))
	                .build();
		PushResult result=jPushCilent.sendPush(payload);
		System.err.println("s:="+result);
		/*PushPayload payload=PushPayload.alertAll("我输出了"); 
		PushResult result=jPushCilent.sendPush(payload);
		System.err.println("s:="+result);*/
	}
	public static void push2() throws APIConnectionException, APIRequestException{
	/*	String materSecret="1dd0e3924e7394137bc20d57";
		String appKey="8f6965a441a0aa10011c7063";*/
		//阿姨
		String materSecret="b2588d7dcaa473f3975c86fc";
		String appKey="587fc17e9c0cc048c2a3e10a";
		JPushClient jPushCilent=new JPushClient(materSecret,appKey);
		PushPayload payload=push_Android("XXXX");
		PushResult result=jPushCilent.sendPush(payload);
		System.err.println("s:="+result);
		/*PushPayload payload=PushPayload.alertAll("我输出了"); 
		PushResult result=jPushCilent.sendPush(payload);
		System.err.println("s:="+result);*/
	}
	public static void push4() throws APIConnectionException, APIRequestException{
		String materSecret="1dd0e3924e7394137bc20d57";
		String appKey="8f6965a441a0aa10011c7063";
		//阿姨
		/*String materSecret="b2588d7dcaa473f3975c86fc";
		String appKey="587fc17e9c0cc048c2a3e10a";*/
		JPushClient jPushCilent=new JPushClient(materSecret,appKey);
		PushPayload payload=PushPayload.newBuilder()
                .setPlatform(Platform.android_ios())
                .setAudience(Audience.alias("15858830325"))
                .setNotification(Notification.newBuilder()
                        .addPlatformNotification(AndroidNotification.newBuilder()
                                .addExtra("type", "infomation")
                                .setAlert("XXX")
                                .build())
                        .addPlatformNotification(IosNotification.newBuilder()
                                .addExtra("type", "infomation")
                                .setAlert("XXX")
                                .addExtra("NAME", "xxx")
                                .build())
                        .build())
                .setOptions(Options.newBuilder()
                        .setApnsProduction(false)//true-推送生产环境 false-推送开发环境（测试使用参数）
                        .setTimeToLive(90)//消息在JPush服务器的失效时间（测试使用参数）
                        .build())
                .build();
		PushResult result=jPushCilent.sendPush(payload);
		System.err.println("s:="+result);
		/*PushPayload payload=PushPayload.alertAll("我输出了"); 
		PushResult result=jPushCilent.sendPush(payload);
		System.err.println("s:="+result);*/
	}
	
	 //发送自定义消息
    private static PushPayload push_Android(String message) {  
        Map<String,String> map = new HashMap<>();
        map.put("测试", "测试1");
        Builder msg = Message.newBuilder();
        msg.setTitle("衡云title");
        msg.setMsgContent("衡云content");
        msg.setContentType("type:1");
        msg.addExtra("type", 1);
        
//        Message.newBuilder();
        return PushPayload.newBuilder()  
                .setPlatform(Platform.all())  
                .setAudience(Audience.alias("15356506227"))  
                .setMessage(msg.build())
                .build();  
    }
	
	
}